$(function () {
    $("#continue").click(function () {
        var actual_name = $("#actual_name").val();
        var ifsc_code = $("#ifsc_code").val();
        var bank_name = $("#bank_name").val();
        var bank_account = $("#bank_account").val();
        var bank_account_confirm = $("#bank_account_confirm").val();
        var email = $("#email").val();
        var upi_address = $("#upi_address").val();
        var upi_address_confirm = $("#upi_address_confirm").val();

        if (actual_name == '' || actual_name == undefined || actual_name == null) {
            toast("actual_name is required!")
            return;
        }
        if (ifsc_code == '' || ifsc_code == undefined || ifsc_code == null) {
            toast("ifsc_code is required!")
            return;
        }
        if (bank_name == '' || bank_name == undefined || bank_name == null) {
            toast("bank_name is required!")
            return;
        }
        if (bank_account == '' || bank_account == undefined || bank_account == null) {
            toast("bank_account is required!")
            return;
        }
        if (bank_account_confirm == '' || bank_account_confirm == undefined || bank_account_confirm == null) {
            toast("bank_account_confirm is required!")
            return;
        } else {
            if (bank_account != bank_account_confirm) {
                toast("bank account is inconsistent!")
                return;
            }
        }
        if (email == '' || email == undefined || email == null) {
            toast("email is required!")
            return;
        }
        if (upi_address == '' || upi_address == undefined || upi_address == null) {
            toast("upi_address is required!")
            return;
        }
        if (upi_address_confirm == '' || upi_address_confirm == undefined || upi_address_confirm == null) {
            toast("upi_address_confirm is required!")
            return;
        } else {
            if (upi_address_confirm != upi_address) {
                toast("upi-address is inconsistent!")
                return;
            }
        }

        // var form = $('#form-bank').serialize();
        var data = {
            actualName: actual_name,
            ifscCode: ifsc_code,
            bankName: bank_name,
            bankAccount: bank_account,
            email: email,
            upiAddress: upi_address
        }
        $.ajax({
            type: "POST",
            url: "../bank/saveBank",
            dataType: "json",
            contentType: "application/json",
            data: JSON.stringify(data),
            success: function (msg) {
                var f = msg.data;
                if (f) {
                    toast("SUCCESS!");
                    window.location.href = 'withdrawal';
                }
            }
        })

    })

    $("#back_nav_bar").click(function () {
        window.location.href = "withdrawal";
    })

})